#ifndef   	COMPOSITE_PARSER_H
#define   	COMPOSITE_PARSER_H

#include "parser.h"

namespace eg {

using namespace std;

//==================================================================================================
//                                  composite parsers
//==================================================================================================

// Base (abstract class) for composite parsers (sequence and ordered choice)
class composite_parser: public parser {
public:
	composite_parser() {
	}
	~composite_parser() {
		/*for (list<parser *>::iterator i = parsers.begin(); i != parsers.end(); i++)
		 if ( !(*i)->is_a_rule() ) delete *i; */
	}

	void add_parser(parser *p) {
		parsers.push_back(p);
	}

protected:

	list<parser *> parsers;
};

// A sequence parser: E = E1 E2 ... En
class seq_parser: public composite_parser {

public:

	bool parse(bool gen_ast = true);

	string to_string();

	// concatenation operator (sequence)
	parser & operator >>(parser & p);

	// ordered choice operator
	parser & operator|(parser & p);

	bool left_recursive(parser * from);

};

// A ordered choice parser: E = E1 / E2 / ... / En
class alt_parser: public composite_parser {

public:

	bool parse(bool gen_ast = true);

	string to_string();

	// ordered choice operator
	parser & operator|(parser & p);

	bool left_recursive(parser * from);

};

}

#endif 	    // !EG_H
